package me.wenshan.demo.webdemo;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class LoginServlet
 */


public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public LoginServlet() {
        super();

    }


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out=response.getWriter();
		String name=request.getParameter("uid");
		String pwd=request.getParameter("upwd");
		
		HttpSession session = request.getSession(true);
		Object userVal = session.getAttribute("user");
		if (userVal != null)
		{
			out.print("已经登录");
		}
		else if (name.compareTo("jetlan") == 0 && pwd.compareTo("jetlan") == 0)
		{
			session.setAttribute("user", 1);
			out.print("登录成功");
		}
		else
		{
			out.print("登录失败");
		}
		
		out.flush();
		out.close();
	}

}
